<template>
    <div>
      <div class="top-panel">
        <el-card>
          <el-form :model="searchForm" label-width="100px" label-position="right">
            <el-row>
              <el-col :span="5">
                <el-form-item label="活动编号">
                  <el-input
                    class="password-input"
                    v-model="searchForm.activityIdFuzzy"
                    clearable
                    placeholder="支持模糊搜索"
                    @keyup.enter="loadDataList"
                  >
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="5">
                <el-form-item label="活动名称">
                  <el-input
                    class="password-input"
                    v-model="searchForm.title"
                    clearable
                    placeholder="支持模糊搜索"
                    @keyup.enter="loadDataList"
                  >
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4" :style="{ paddingLeft: '10px',paddingTop:'4px' }">
                <el-button type="success" @click="loadDataList()"
                  >查询
                </el-button>
              </el-col>
            </el-row>
          </el-form>
        </el-card>
      </div>
      <el-card class="table-data-card">
        <template #header>
          <span>申请列表</span>
        </template>
        <Table
          ref="tableInfoRef"
          :columns="columns"
          :fetch="loadDataList"
          :dataSource="tableData"
          :options="tableOptions"
          :extHeight="tableOptions.extHeight"
        >
        </Table>
      </el-card>
    </div>
  </template>
  <script setup>
  import { getCurrentInstance, nextTick, ref } from "vue";
  const { proxy } = getCurrentInstance();
  import { ElMessage, ElMessageBox } from 'element-plus'
  const userInfo = ref(proxy.VueCookies.get("userInfo") || {});

  const api = {
    loadDataList: "/record/loadMyRecordList",
  };
  const searchForm = ref({
    status:-1,
  });

  const statusArray=[
    {value:-1,label:"全部"},
    {value:0,label:"待审核"},
    {value:1,label:"已通过"},
    {value:2,label:"已驳回"},

  ];


  const tableData = ref({});
  const tableOptions = ref({
    extHeight: 125,
  });

  const columns = [

    {
      label: "志愿者编号",
      prop: "userId",
    },
    {
      label: "姓名",
      prop: "name",
    },

    {
      label: "活动编号",
      prop: "activityId",
    },
    {
      label: "活动名称",
      prop: "activityTitle",
    },
    {
      label: "志愿时长(h)",
      prop: "hours",
    },
    {
      label: "完成时间",
      prop: "recordTime",

    },
  ];

  const tableInfoRef = ref();

  const loadDataList = async () => {
    let params = {
      pageNo: tableData.value.pageNo,
      pageSize: tableData.value.pageSize,
    };
    Object.assign(params, searchForm.value);
    if(params.status===-1){
      delete params.status;
    }
    let result = await proxy.Request({
      url: api.loadDataList,
      params: params,
    });
    if (!result) {
      return;
    }
    Object.assign(tableData.value, result.data);
  };


  //反馈信息
  const feedback=ref(null);
  //修改申请状态
  const updateStatus = (data,status) => {
    let info=status==1?"通过":"驳回";
    proxy.Confirm(`确定【${info}】【${data.name}】对【${data.activityName}】的申请吗？`, async () => {
      let result = await proxy.Request({
        url: api.updateStatus,
        params: {
            applyId: data.applyId,
            status,status,
            feedback:feedback.value,
        },
      });
      if (!result) {
        return;
      }
      proxy.Message.success("操作成功");
      loadDataList();
    });
  };

  const openFeedBackInfo = (data,status) => {
  ElMessageBox.prompt('请输入反馈信息', 'Tip', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
  })
    .then(({ value }) => {
        feedback.value=value;
        updateStatus(data,status);
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: 'Input canceled',
      })
    })
}

  </script>

  <style lang="scss" scoped>
  .detail-tree-panel {
    height: calc(100vh - 273px);
    overflow: auto;
    width: 100%;
  }
  </style>
